import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _forEach from "lodash/forEach";
import _isNumber from "lodash/isNumber";
import _map from "lodash/map";

/**
 * Row
 * @date 2018/10/10
 */
import React from 'react';
import { Row as CpaasRow } from 'antd';
import Col from "./Col";

var Row = /*#__PURE__*/function (_React$Component) {
  _inherits(Row, _React$Component);

  var _super = _createSuper(Row);

  function Row(props) {
    var _this;

    _classCallCheck(this, Row);

    _this = _super.call(this, props);
    _this.state = {
      willRemovePositionY: -1
    };
    _this.handleUpdateWillRemovePositionY = _this.handleUpdateWillRemovePositionY.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(Row, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          _this$props$cols = _this$props.cols,
          cols = _this$props$cols === void 0 ? [] : _this$props$cols,
          rowCount = _this$props.rowCount,
          component = _this$props.component,
          onRemoveField = _this$props.onRemoveField,
          wrapperFieldComponent = _this$props.wrapperFieldComponent,
          colLayout = _this$props.colLayout,
          fieldLabelWidth = _this$props.fieldLabelWidth,
          rowIndex = _this$props.rowIndex,
          currentEditField = _this$props.currentEditField,
          onUpdateComponent = _this$props.onUpdateComponent,
          willRemovePositionX = _this$props.willRemovePositionX,
          positionY = _this$props.positionY,
          onUpdateWillRemovePositionX = _this$props.onUpdateWillRemovePositionX,
          onRefreshTemplate = _this$props.onRefreshTemplate;
      var willRemovePositionY = this.state.willRemovePositionY;
      var colCount = 0;

      _forEach(cols, function (c) {
        if (c.colspan && _isNumber(c.colspan)) {
          colCount += c.colspan;
        } else {
          colCount += 1;
        }
      });

      var positionX = 0;

      var colElements = _map(cols, function (c, colIndex) {
        var positionRightX = positionX;

        if (c.colspan && _isNumber(c.colspan)) {
          positionRightX += c.colspan;
        } else {
          positionRightX += 1;
        }

        var colElement = /*#__PURE__*/React.createElement(Col, {
          key: colIndex,
          rowIndex: rowIndex,
          colIndex: colIndex,
          rowCount: rowCount,
          colCount: colCount,
          component: c,
          pComponent: component,
          onRemoveField: onRemoveField,
          wrapperFieldComponent: wrapperFieldComponent,
          colLayout: colLayout,
          fieldLabelWidth: fieldLabelWidth,
          currentEditField: currentEditField,
          onUpdateComponent: onUpdateComponent // 删除
          ,
          willRemovePositionY: willRemovePositionY,
          willRemovePositionX: willRemovePositionX,
          positionY: positionY,
          positionX: positionX,
          positionRightX: positionRightX,
          onUpdateWillRemovePositionX: onUpdateWillRemovePositionX,
          onUpdateWillRemovePositionY: _this2.handleUpdateWillRemovePositionY,
          onRefreshTemplate: onRefreshTemplate
        });
        positionX = positionRightX;
        return colElement;
      });

      return /*#__PURE__*/React.createElement(CpaasRow, {
        type: "flex"
      }, colElements);
    }
  }, {
    key: "handleUpdateWillRemovePositionY",
    value: function handleUpdateWillRemovePositionY() {
      var willRemovePositionY = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
      this.setState({
        willRemovePositionY: willRemovePositionY
      });
    }
  }]);

  return Row;
}(React.Component);

export { Row as default };

if (process.env.NODE_ENV !== 'production') {
  Row.displayName = 'DynamicForm(Row)';
}